package com.jushu.storbox.handler;

import android.content.Context;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.widget.Toast;

import com.jushu.storbox.R;
import com.jushu.storbox.constant.ErrorConstant;
import com.jushu.storbox.constant.MessageCode;
import com.jushu.storbox.util.LogUtil;
import com.jushu.storbox.util.PublicTools;
import com.jushu.storbox.util.ToastFrequencyUtil;
import com.huawei.sharedrive.sdk.android.common.ErrorCode;
import com.huawei.sharedrive.sdk.android.exception.ClientException;

public abstract class ClientExceptionRelateHandler extends Handler {

	public final static int CLIENT_EXCEPTION_OCCURED = ErrorCode.GENERAL_EXCEPTION;
	
	// ==================400==========================
	public final static int ERROR_CODE_400_PARAMS = 400;
	public final static String InvalidParameter = "InvalidParameter";
	public final static String InvalidPart = "InvalidPart";
	public final static String InvalidRange = "InvalidRange";
	public final static String InvalidTeamRole = "InvalidTeamRole";
	public final static String InvalidRegion = "InvalidRegion";
	public final static String InvalidPermissionRole = "InvalidPermissionRole";
	public final static String InvalidFileType = "InvalidFileType";
	public final static String UnmatchedDownloadUrl = "UnmatchedDownloadUrl";

	// ==================401==========================
	public final static int ERROR_CODE_401_UNAUTHORIZED = 401;
	public final static String Unauthorized = "Unauthorized";
	public final static String ClientUnauthorized = "ClientUnauthorized";

	// ==================403==========================
	public final static int ERROR_CODE_403_NO_RIGHT = 403;
	public final static String Forbidden = "Forbidden";
	public final static String UserLocked = "UserLocked";
	public final static String InvalidSpaceStatus = "InvalidSpaceStatus";
	public final static String SourceForbidden = "SourceForbidden";
	public final static String DestForbidden = "DestForbidden";
	public final static String UserDisabled = "UserDisabled";
    
	// ==================404==========================
	public final static int ERROR_CODE_404_NO_RESOURCE = 404;
	public final static String NoSuchUser = "NoSuchUser";
	public final static String NoSuchItem = "NoSuchItem";
	public final static String NoSuchFolder = "NoSuchFolder";
	public final static String NoSuchFile = "NoSuchFile";
	public final static String NoSuchVersion = "NoSuchVersion";
	public final static String NoSuchToken = "NoSuchToken";
	public final static String NoSuchLink = "NoSuchLink";
	public final static String NoSuchShare = "NoSuchShare";
	public final static String NoSuchRegion = "NoSuchRegion";
	public final static String NoSuchParent = "NoSuchParent";
	public final static String NoSuchApplication = "NoSuchApplication";
	public final static String LinkNotEffective = "LinkNotEffective";
	public final static String LinkExpired = "LinkExpired";
	public final static String NoSuchSource = "NoSuchSource";
	public final static String NoSuchDest = "NoSuchDest";
	public final static String NoThumbnail = "NoThumbnail";
	public final static String NoSuchOption = "NoSuchOption";
	public final static String AbnormalTeamStatus = "AbnormalTeamStatus";
	public final static String NoSuchGroup = "NoSuchGroup";
	public final static String NoSuchMember = "NoSuchMember";
	public final static String AbnormalGroupStatus = "AbnormalGroupStatus";
	public final static String NoSuchTeamspace = "NoSuchTeamspace";
	public final static String NoSuchClient = "NoSuchClient";
	public final static String NoSuchACL = "NoSuchACL";
	public final static String CallbackFailed = "CallbackFailed";

	// ==================405==========================
	public final static int ERROR_CODE_405_NOT_ALLOWED = 405;
	public final static String MethodNotAllowed = "MethodNotAllowed";
	public final static String InvalidProtocol = "InvalidProtocol";
	public final static String InvalidLicense = "InvalidLicense";

	// ==================409==========================
	public final static int ERROR_CODE_409_SOURCE_CONFLICT = 409;
	public final static String Conflict = "Conflict";
	public final static String ConflictUser = "ConflictUser";
	public final static String RepeatNameConflict = "RepeatNameConflict";
	public final static String SubFolderConflict = "SubFolderConflict";
	public final static String SameParentConflict = "SameParentConflict";
	public final static String LinkExistedConflict = "LinkExistedConflict";
	public final static String ExistMemberConflict = "ExistMemberConflict";
	public final static String ExistTeamspaceConflict = "ExistTeamspaceConflict";
	public final static String AsyncNodesConflict = "AsyncNodesConflict";
	public final static String ExceedQuota = "ExceedQuota";
	public final static String SameNodeConflict = "SameNodeConflict";

	// ==================412==========================
	public final static int ERROR_CODE_412_REQUEST = 412;
	public final static String TooManyRequests = "TooManyRequests";
	public final static String PreconditionFailed = "PreconditionFailed";
	
	public final static int ERROR_CODE_417_EXCEPT_RESULT = 417;
	public final static String transactionCommitError = "transactionCommitError";
	public final static String transactionRollbackError = "transactionRollbackError";
	// ==================500==========================
	public final static int ERROR_CODE_500_INNER_ERROR = 500;
	public final static String InternalServerError = "InternalServerError";
	
	// ==================503==========================
	public final static int ERROR_CODE_503_SERVER_UNAVALIABLE = 503;

	// ==================507==========================
	public final static int ERROR_CODE_507_SERVER_SAVE = 507;
	public final static String InsufficientStorage = "InsufficientStorage";

	public final static int ERROR_CODE_901_SERVER_UNAVALIABLE = ErrorCode.SERVER_ERROR;
	public final static int ERROR_CODE_909_CONNECT_TIMEOUT = ErrorCode.CONNECT_TIMEOUT_ERROR;
	public final static int ERROR_CODE_910_REQUEST_TIMEOUT = ErrorCode.REQUEST_TIMEOUT_ERROR;
	public final static int ERROR_CODE_900_SERVER_ADDRESS_UnVALIDE = ErrorCode.SERVER_ADDRESS_EMPTY;
	
	public final static int ERROR_CODE_10001_CLIENT_LOGIN_INFO = ErrorConstant.CLIENT_ERROR_LOGIN_INFO;
	
	private static final String TAG = ClientExceptionRelateHandler.class.getSimpleName();
	
	private Context mContext = null;
	
	public abstract Context getContext();
	
	@Override
	public void handleMessage(Message msg) {
		ClientException exception = null;
		int switchParam = 0;
		
		if(msg.obj instanceof ClientException) {
			exception = (ClientException) msg.obj;
			switchParam = exception.getStatusCode();
		}
		
		String errorCode = "";
		if(exception != null){
			errorCode = exception.getCode();
		}else if(msg.getData() != null){
			errorCode = msg.getData().getString("code");
		}
		
		switchParam = (switchParam == 0 ? msg.what: switchParam);
		
		onHandlerBefore(msg, errorCode);
		
		switch (switchParam) {
			case MessageCode.NETWORK_EXCEPTION:
				onException_NoNetwork();
				break;
			case ERROR_CODE_400_PARAMS:
				if(InvalidParameter.equals(errorCode)) {
					onException_400_InvalidParameter(msg,errorCode);
				} else if(InvalidPart.equals(errorCode)) {
					onException_400_InvalidPart(msg,errorCode);
				} else if(InvalidRange.equals(errorCode)) {
					onException_400_InvalidRange(msg,errorCode);
				} else if(InvalidTeamRole.equals(errorCode)) {
					onException_400_InvalidTeamRole(msg,errorCode);
				} else if(InvalidRegion.equals(errorCode)) {
					onException_400_InvalidRegion(msg,errorCode);
				} else if(InvalidPermissionRole.equals(errorCode)) {
					onException_400_InvalidPermissionRole(msg,errorCode);
				} else if(InvalidFileType.equals(errorCode)) {
					onException_400_InvalidFileType(msg,errorCode);
				} else if(UnmatchedDownloadUrl.equals(errorCode)) {
					onException_400_UnmatchedDownloadUrl(msg,errorCode);
				} else {
					onException_400_UnknowException(msg,errorCode);
				}
				break;
	
			case ERROR_CODE_401_UNAUTHORIZED:
				if(Unauthorized.equals(errorCode)) {
					onException_401_Unauthorized(msg,errorCode);
				} else if(ClientUnauthorized.equals(errorCode)) {
					onException_401_ClientUnauthorized(msg,errorCode);
				} else {
					onException_401_UnknowException(msg,errorCode);
				}
				break;
	
			case ERROR_CODE_403_NO_RIGHT:
				if(Forbidden.equals(errorCode)) {
					onException_403_Forbidden(msg,errorCode);
				} else if(UserLocked.equals(errorCode)) {
					onException_403_UserLocked(msg,errorCode);
				} else if(InvalidSpaceStatus.equals(errorCode)) {
					onException_403_InvalidSpaceStatus(msg,errorCode);
				} else if(SourceForbidden.equals(errorCode)) {
					onException_403_SourceForbidden(msg,errorCode);
				} else if(DestForbidden.equals(errorCode)) {
					onException_403_DestForbidden(msg,errorCode);
				} else if(UserDisabled.equals(errorCode)) {
					onException_403_UserDisabled(msg,errorCode);
				} else {
					onException_403_UnknowException(msg,errorCode);
				}
				break;
	
			case ERROR_CODE_404_NO_RESOURCE:
				if(NoSuchUser.equals(errorCode)) {
					onException_404_NoSuchUser(msg,errorCode);
				} else if(NoSuchItem.equals(errorCode)) {
					onException_404_NoSuchItem(msg,errorCode);
				} else if(NoSuchFolder.equals(errorCode)) {
					onException_404_NoSuchFolder(msg,errorCode);
				} else if(NoSuchFile.equals(errorCode)) {
					onException_404_NoSuchFile(msg,errorCode);
				} else if(NoSuchVersion.equals(errorCode)) {
					onException_404_NoSuchVersion(msg,errorCode);
				} else if(NoSuchToken.equals(errorCode)) {
					onException_404_NoSuchToken(msg,errorCode);
				} else if(NoSuchLink.equals(errorCode)) {
					onException_404_NoSuchLink(msg,errorCode);
				} else if(NoSuchShare.equals(errorCode)) {
					onException_404_NoSuchShare(msg,errorCode);
				} else if(NoSuchRegion.equals(errorCode)) {
					onException_404_NoSuchRegion(msg,errorCode);
				} else if(NoSuchParent.equals(errorCode)) {
					onException_404_NoSuchParent(msg,errorCode);
				} else if(NoSuchApplication.equals(errorCode)) {
					onException_404_NoSuchApplication(msg,errorCode);
				} else if(LinkNotEffective.equals(errorCode)) {
					onException_404_LinkNotEffective(msg,errorCode);
				} else if(LinkExpired.equals(errorCode)) {
					onException_404_LinkExpired(msg,errorCode);
				} else if(NoSuchSource.equals(errorCode)) {
					onException_404_NoSuchSource(msg,errorCode);
				} else if(NoSuchDest.equals(errorCode)) {
					onException_404_NoSuchDest(msg,errorCode);
				} else if(NoThumbnail.equals(errorCode)) {
					onException_404_NoThumbnail(msg,errorCode);
				} else if(NoSuchOption.equals(errorCode)) {
					onException_404_NoSuchOption(msg,errorCode);
				} else if(AbnormalTeamStatus.equals(errorCode)) {
					onException_404_AbnormalTeamStatus(msg,errorCode);
				} else if(NoSuchGroup.equals(errorCode)) {
					onException_404_NoSuchGroup(msg,errorCode);
				} else if(NoSuchMember.equals(errorCode)) {
					onException_404_NoSuchMember(msg,errorCode);
				} else if(AbnormalGroupStatus.equals(errorCode)) {
					onException_404_AbnormalGroupStatus(msg,errorCode);
				} else if(NoSuchTeamspace.equals(errorCode)) {
					onException_404_NoSuchTeamspace(msg,errorCode);
				} else if(NoSuchClient.equals(errorCode)) {
					onException_404_NoSuchClient(msg,errorCode);
				} else if(NoSuchACL.equals(errorCode)) {
					onException_404_NoSuchACL(msg,errorCode);
				} else if(CallbackFailed.equals(errorCode)) {
					onException_404_CallbackFailed(msg,errorCode);
				} else {
					onException_404_UnknowException(msg,errorCode);
				}
				break;
	
			case ERROR_CODE_405_NOT_ALLOWED:
				if(MethodNotAllowed.equals(errorCode)) {
					onException_405_MethodNotAllowed(msg,errorCode);
				} else if(InvalidProtocol.equals(errorCode)) {
					onException_405_InvalidProtocol(msg,errorCode);
				} else if(InvalidLicense.equals(errorCode)) {
					onException_405_InvalidLicense(msg,errorCode);
				} else {
					onException_405_UnknowException(msg,errorCode);
				}
				break;
	
			case ERROR_CODE_409_SOURCE_CONFLICT:
				if(Conflict.equals(errorCode)) {
					onException_409_Conflict(msg,errorCode);
				} else if(ConflictUser.equals(errorCode)) {
					onException_409_ConflictUser(msg,errorCode);
				} else if(RepeatNameConflict.equals(errorCode)) {
					onException_409_RepeatNameConflict(msg,errorCode);
				} else if(SubFolderConflict.equals(errorCode)) {
					onException_409_SubFolderConflict(msg,errorCode);
				} else if(SameParentConflict.equals(errorCode)) {
					onException_409_SameParentConflict(msg,errorCode);
				} else if(LinkExistedConflict.equals(errorCode)) {
					onException_409_LinkExistedConflict(msg,errorCode);
				} else if(ExistMemberConflict.equals(errorCode)) {
					onException_409_ExistMemberConflict(msg,errorCode);
				} else if(ExistTeamspaceConflict.equals(errorCode)) {
					onException_409_ExistTeamspaceConflict(msg,errorCode);
				} else if(AsyncNodesConflict.equals(errorCode)) {
					onException_409_AsyncNodesConflict(msg,errorCode);
				} else if(ExceedQuota.equals(errorCode)) {
					onException_409_ExceedQuota(msg,errorCode);
				} else if(SameNodeConflict.equals(errorCode)) {
					onException_409_SameNodeConflict(msg,errorCode);
				} else {
					onException_409_UnknowException(msg,errorCode);
				}
				break;
	
			case ERROR_CODE_412_REQUEST:
				if(TooManyRequests.equals(errorCode)) {
					onException_412_TooManyRequests(msg,errorCode);
				} else if(PreconditionFailed.equals(errorCode)) {
					onException_412_PreconditionFailed(msg,errorCode);
				} else {
					onException_412_UnknowException(msg,errorCode);
				}
				break;
			case ERROR_CODE_417_EXCEPT_RESULT:
				if(transactionCommitError.equals(errorCode)) {
					onException_417_transactionCommitError(msg,errorCode);
				} else if(transactionRollbackError.equals(errorCode)) {
					onException_417_transactionRollbackError(msg,errorCode);
				} else {
					onException_417_UnknowException(msg,errorCode);
				}
				break;
				
			case ERROR_CODE_500_INNER_ERROR:
				if(InternalServerError.equals(errorCode)) {
					onException_500_InternalServerError(msg,errorCode);
				} else {
					onException_500_UnknowException(msg,errorCode);
				}
				break;
				
			case ERROR_CODE_503_SERVER_UNAVALIABLE:
				onException_503_ServerUnavaliable(msg,errorCode);
				break;
				
			case ERROR_CODE_507_SERVER_SAVE:
				if(InsufficientStorage.equals(errorCode)) {
					onException_507_InsufficientStorage(msg,errorCode);
				} else {
					onException_507_UnknowException(msg,errorCode);
				}
				break;
				
			case ERROR_CODE_900_SERVER_ADDRESS_UnVALIDE:
				onException_900_ServerAddressUnavaliable(msg,errorCode);
				break;
				
			case ERROR_CODE_901_SERVER_UNAVALIABLE:
				onException_901_ServerUnavaliable(msg,errorCode);
				break;
				
			case ERROR_CODE_909_CONNECT_TIMEOUT:
				onException_909_ConnectTimeout(msg,errorCode);
				break;
				
			case ERROR_CODE_910_REQUEST_TIMEOUT:
				onException_910_RequestTimeout(msg,errorCode);
				break;
				
			case ERROR_CODE_10001_CLIENT_LOGIN_INFO:
				onException_10001_InvaliedLoginInfo(msg,errorCode);
				break;
				
			default:
				onException_Other(msg,errorCode);
				super.handleMessage(msg);
		}
	}
	
	protected void onException_10001_InvaliedLoginInfo(Message msg,
			String errorCode) {
		final Context context = getContext();
		if(context != null) {
			PublicTools.restartApp(context);
		} else {
			LogUtil.e(TAG, "error login info!");
		}
	}
	
	protected void onException_910_RequestTimeout(Message msg,
			String errorCode) {
		showToast(R.string.request_server_timeout,Toast.LENGTH_SHORT);
	}

	protected void onException_909_ConnectTimeout(Message msg,
			String errorCode) {
		showToast(R.string.connect_server_timeout,Toast.LENGTH_SHORT);
	}

	protected void onException_403_UserDisabled(Message msg,
			String errorCode) {
		LogUtil.e("403",errorCode);
	}

	protected void onException_417_UnknowException(Message msg,
			String errorCode) {
		showToast(R.string.unknown_error,Toast.LENGTH_SHORT, 417, errorCode);
	}

	protected void onException_417_transactionRollbackError(Message msg,
			String errorCode) {
		showToast(R.string.object_submit_failed,Toast.LENGTH_SHORT);
	}

	protected void onException_417_transactionCommitError(Message msg,
			String errorCode) {
		showToast(R.string.object_submit_failed,Toast.LENGTH_SHORT);
	}

	protected void onException_503_ServerUnavaliable(Message msg,
			String errorCode) {
		showToast(R.string.serve_is_not_availible, Toast.LENGTH_SHORT);;
	}
	
	protected void onException_900_ServerAddressUnavaliable(Message msg,
			String errorCode) {
		showToast(R.string.server_address_is_unavailable,Toast.LENGTH_SHORT);
	}
	
	protected void onException_901_ServerUnavaliable(Message msg,
			String errorCode) {
		showToast(R.string.loginwait_activity_server_not_response,Toast.LENGTH_SHORT);
	}

	protected void onHandlerBefore(Message msg, String errorCode) {
		
	}

	protected void onException_400_UnknowException(Message msg,
			String errorCode) {
		showToast(R.string.unknown_error,Toast.LENGTH_SHORT,400, errorCode);
	}

	protected void onException_401_UnknowException(Message msg,
			String errorCode) {
		showToast(R.string.unknown_error,Toast.LENGTH_SHORT, 401, errorCode);
	}

	protected void onException_403_UnknowException(Message msg,
			String errorCode) {
		showToast(R.string.unknown_error,Toast.LENGTH_SHORT, 403, errorCode);
	}

	protected void onException_404_UnknowException(Message msg,
			String errorCode) {
		showToast(R.string.unknown_error,Toast.LENGTH_SHORT, 404, errorCode);
	}

	protected void onException_405_UnknowException(Message msg,
			String errorCode) {
		showToast(R.string.unknown_error,Toast.LENGTH_SHORT, 405, errorCode);
	}

	protected void onException_409_UnknowException(Message msg,
			String errorCode) {
		showToast(R.string.unknown_error,Toast.LENGTH_SHORT, 409, errorCode);
	}

	protected void onException_412_UnknowException(Message msg,
			String errorCode) {
		showToast(R.string.unknown_error,Toast.LENGTH_SHORT, 412, errorCode);
	}

	protected void onException_500_UnknowException(Message msg,
			String errorCode) {
		showToast(R.string.unknown_error,Toast.LENGTH_SHORT,500, errorCode);
	}

	protected void onException_507_UnknowException(Message msg,
			String errorCode) {
		showToast(R.string.unknown_error,Toast.LENGTH_SHORT,507, errorCode);
	}

	protected void onException_Other(Message msg, String errorCode) {
		//showToast(R.string.unknown_error,Toast.LENGTH_SHORT);
	}

	protected void onException_400_InvalidParameter(Message msg, String errorCode) {
		showToast(R.string.param_error,Toast.LENGTH_SHORT);
	}
	
	protected void onException_NoNetwork() {
		showToast(R.string.allfile_notwork_obstructed,Toast.LENGTH_SHORT);
	}

	protected void onException_400_InvalidPart(Message msg, String errorCode) {
		showToast(R.string.part_is_not_availible,Toast.LENGTH_SHORT);
	}

	protected void onException_400_InvalidRange(Message msg, String errorCode) {
		showToast(R.string.part_is_not_availible,Toast.LENGTH_SHORT);
	}

	protected void onException_400_InvalidTeamRole(Message msg, String errorCode) {
	}

	protected void onException_400_InvalidRegion(Message msg, String errorCode) {
	}

	protected void onException_400_InvalidPermissionRole(Message msg, String errorCode) {
	}

	protected void onException_400_InvalidFileType(Message msg, String errorCode) {
	}

	protected void onException_400_UnmatchedDownloadUrl(Message msg, String errorCode) {
		showToast(R.string.request_error, Toast.LENGTH_SHORT);
	}

	protected void onException_401_Unauthorized(Message msg, String errorCode) {
		showToast(R.string.authorized_failed,Toast.LENGTH_SHORT);
	}

	protected void onException_401_ClientUnauthorized(Message msg, String errorCode) {
		showToast(R.string.device_is_disabled,Toast.LENGTH_SHORT);
	}

	protected void onException_403_Forbidden(Message msg, String errorCode) {
		showToast(R.string.method_is_forbiden,Toast.LENGTH_SHORT);
	}

	protected void onException_403_UserLocked(Message msg, String errorCode) {
		showToast(R.string.login_locked_window_message,Toast.LENGTH_SHORT);
	}

	protected void onException_403_InvalidSpaceStatus(Message msg, String errorCode) {
	}

	protected void onException_403_SourceForbidden(Message msg, String errorCode) {
	}

	protected void onException_403_DestForbidden(Message msg, String errorCode) {
	}

	protected void onException_404_NoSuchUser(Message msg, String errorCode) {
		showToast(R.string.user_is_not_exist,Toast.LENGTH_SHORT);
	}

	protected void onException_404_NoSuchItem(Message msg, String errorCode) {
		showToast(R.string.resource_is_not_exist,Toast.LENGTH_SHORT);
	}

	protected void onException_404_NoSuchFolder(Message msg, String errorCode) {
		showToast(R.string.folder_is_not_exist,Toast.LENGTH_SHORT);
	}

	protected void onException_404_NoSuchFile(Message msg, String errorCode) {
		showToast(R.string.file_is_not_exist,Toast.LENGTH_SHORT);
	}

	protected void onException_404_NoSuchVersion(Message msg, String errorCode) {
		showToast(R.string.version_is_not_exist,Toast.LENGTH_SHORT);
	}

	protected void onException_404_NoSuchToken(Message msg, String errorCode) {
		showToast(R.string.token_is_not_exist,Toast.LENGTH_SHORT);
	}

	protected void onException_404_NoSuchLink(Message msg, String errorCode) {
		showToast(R.string.link_is_disable,Toast.LENGTH_SHORT);
	}

	protected void onException_404_NoSuchShare(Message msg, String errorCode) {
		showToast(R.string.share_is_not_exist,Toast.LENGTH_SHORT);
	}

	protected void onException_404_NoSuchRegion(Message msg, String errorCode) {
	}

	protected void onException_404_NoSuchParent(Message msg, String errorCode) {
	}

	protected void onException_404_NoSuchApplication(Message msg, String errorCode) {
	}

	protected void onException_404_LinkNotEffective(Message msg, String errorCode) {
		showToast(R.string.link_is_effect,Toast.LENGTH_SHORT);
	}

	protected void onException_404_LinkExpired(Message msg, String errorCode) {
		showToast(R.string.link_is_disable,Toast.LENGTH_SHORT);
	}

	protected void onException_404_NoSuchSource(Message msg, String errorCode) {
		showToast(R.string.resource_is_not_availible, Toast.LENGTH_SHORT);
	}

	protected void onException_404_NoSuchDest(Message msg, String errorCode) {
	}

	protected void onException_404_NoThumbnail(Message msg, String errorCode) {
	}

	protected void onException_404_NoSuchOption(Message msg, String errorCode) {
	}

	protected void onException_404_AbnormalTeamStatus(Message msg, String errorCode) {
	}

	protected void onException_404_NoSuchGroup(Message msg, String errorCode) {
	}

	protected void onException_404_NoSuchMember(Message msg, String errorCode) {
	}

	protected void onException_404_AbnormalGroupStatus(Message msg, String errorCode) {
	}

	protected void onException_404_NoSuchTeamspace(Message msg, String errorCode) {
	}
	
	protected void onException_404_NoSuchClient(Message msg, String errorCode) {
		showToast(R.string.no_client_exist, Toast.LENGTH_SHORT);
	}

	protected void onException_404_NoSuchACL(Message msg, String errorCode) {
	}

	protected void onException_404_CallbackFailed(Message msg, String errorCode) {
		showToast(R.string.teamspace_upload_fail, Toast.LENGTH_SHORT);
	}
	
	protected void onException_405_MethodNotAllowed(Message msg, String errorCode) {
		showToast(R.string.access_is_forbiden, Toast.LENGTH_SHORT);
	}

	protected void onException_405_InvalidProtocol(Message msg, String errorCode) {
	}

	protected void onException_405_InvalidLicense(Message msg, String errorCode) {
	}

	protected void onException_409_Conflict(Message msg, String errorCode) {
	}

	protected void onException_409_ConflictUser(Message msg, String errorCode) {
	}

	protected void onException_409_RepeatNameConflict(Message msg, String errorCode) {
		showToast(R.string.exist_same_resource,Toast.LENGTH_SHORT);
	}

	protected void onException_409_SubFolderConflict(Message msg, String errorCode) {
		showToast(R.string.move_target_is_selfsub,Toast.LENGTH_SHORT);
	}

	protected void onException_409_SameParentConflict(Message msg, String errorCode) {
		showToast(R.string.move_target_no_change,Toast.LENGTH_SHORT);
	}

	protected void onException_409_LinkExistedConflict(Message msg, String errorCode) {
	}

	protected void onException_409_ExistMemberConflict(Message msg, String errorCode) {
	}

	protected void onException_409_ExistTeamspaceConflict(Message msg, String errorCode) {
	}

	protected void onException_409_AsyncNodesConflict(Message msg, String errorCode) {
	}

	protected void onException_409_ExceedQuota(Message msg, String errorCode) {
	}
	
	protected void onException_409_SameNodeConflict(Message msg, String errorCode) {
		showToast(R.string.move_target_is_selfsub,Toast.LENGTH_SHORT);
	}

	protected void onException_412_TooManyRequests(Message msg, String errorCode) {
		showToast(R.string.requset_to_much,Toast.LENGTH_SHORT);
		//showToast(R.string.access_is_forbiden,Toast.LENGTH_SHORT);
	}

	protected void onException_412_PreconditionFailed(Message msg, String errorCode) {
		showToast(R.string.request_preview_conditions_error,Toast.LENGTH_SHORT);
	}

	protected void onException_500_InternalServerError(Message msg, String errorCode) {
		showToast(R.string.server_inner_error, Toast.LENGTH_SHORT);
	}

	protected void onException_507_InsufficientStorage(Message msg, String errorCode) {
	}
	
	protected void showToast(int resId, int duration, int exceptionCode, String errorCode) {
		showToast(resId, duration);
		LogUtil.e(TAG, "code: "+exceptionCode+",error: "+errorCode);
	}
	
	protected void showToast(int resId, int duration) {
		if(mContext == null) {
			mContext = getContext();
		}
		
		if(mContext != null) {
			ToastFrequencyUtil.getInstence().showToast(mContext, resId, duration);
		} else {
			LogUtil.e(TAG,"context is null");
		}
	}
	
	protected void showToast(String message, int duration) {
		if(mContext == null) {
			mContext = getContext();
		}
		if(mContext != null) {
			ToastFrequencyUtil.getInstence().showToast(mContext, message, duration);
		} else {
			LogUtil.e(TAG,"context is null");
		}
	}
}
